import Router from 'vue-router'
import { RawLocation } from 'vue-router/types/index'
import routes from './router'
export class TheRouter extends Router {
  // 调用TheRouter.default()这个静态方法（静态方法不需要实例化）是为了实例化一个对象，
  // 实例化了之后才能继续调用他的实例化方法，就比如我们要调用goToHome这个方法，就用TheRouter.default().goToHome()
  static default(): TheRouter {
    if (!TheRouter.instance_) {
      TheRouter.instance_ = new TheRouter({ routes, mode: 'history' })
    }
    return TheRouter.instance_
  }
  private static instance_: TheRouter
  goToHome() {
    return this._push('/home')
  }
  private _push(
    location: RawLocation
  ): void {
    super.push(location)
  }
}
